/*
 * File: Chart.c
 *
 * Code generated for Simulink model 'Chart'.
 *
 * Model version                  : 1.28
 * Simulink Coder version         : 23.2 (R2023b) 01-Aug-2023
 * C/C++ source code generated on : Mon Dec 23 22:12:51 2024
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives:
 *    1. Execution efficiency
 *    2. RAM efficiency
 * Validation result: Not run
 */

#include "Chart.h"
#include "rtwtypes.h"

/* Named constants for Chart: '<Root>/Chart' */
#define IN_ERROR                       ((uint8_T)1U)
#define IN_IDLE                        ((uint8_T)1U)
#define IN_INIT                        ((uint8_T)2U)
#define IN_NORMAL                      ((uint8_T)3U)
#define IN_NO_ACTIVE_CHILD             ((uint8_T)0U)
#define IN_RUN                         ((uint8_T)2U)

/* Block signals and states (default storage) */
DW rtDW;

/* External inputs (root inport signals with default storage) */
ExtU rtU;

/* External outputs (root outports fed by signals with default storage) */
ExtY rtY;

/* Real-time model */
static RT_MODEL rtM_;
RT_MODEL *const rtM = &rtM_;

/* Model step function */
void Chart_step(void)
{
  /* Chart: '<Root>/Chart' incorporates:
   *  Inport: '<Root>/error_code'
   *  Inport: '<Root>/key_mode'
   *  Outport: '<Root>/g_fsm_s'
   */
  if (rtDW.temporalCounter_i1 < 1U) {
    rtDW.temporalCounter_i1 = 1U;
  }

  if (rtDW.is_active_c3_Chart == 0U) {
    rtDW.is_active_c3_Chart = 1U;
    rtDW.temporalCounter_i1 = 0U;
    rtDW.is_c3_Chart = IN_INIT;
    rtY.g_fsm_s.state = INIT;
    rtY.g_fsm_s.u1_record_data = 1;
  } else {
    switch (rtDW.is_c3_Chart) {
     case IN_ERROR:
      if (rtU.error_signal == 0.0) {
        rtDW.is_c3_Chart = IN_NORMAL;
        switch (rtDW.was_NORMAL) {
         case IN_IDLE:
          rtDW.is_NORMAL = IN_IDLE;
          rtDW.was_NORMAL = IN_IDLE;
          break;

         case IN_RUN:
          rtDW.is_NORMAL = IN_RUN;
          rtDW.was_NORMAL = IN_RUN;
          break;

         default:
          rtDW.is_NORMAL = IN_IDLE;
          rtDW.was_NORMAL = IN_IDLE;
          break;
        }
      }
      break;

     case IN_INIT:
      rtDW.is_c3_Chart = IN_NORMAL;
      switch (rtDW.was_NORMAL) {
       case IN_IDLE:
        rtDW.is_NORMAL = IN_IDLE;
        rtDW.was_NORMAL = IN_IDLE;
        break;

       case IN_RUN:
        rtDW.is_NORMAL = IN_RUN;
        rtDW.was_NORMAL = IN_RUN;
        break;

       default:
        rtDW.is_NORMAL = IN_IDLE;
        rtDW.was_NORMAL = IN_IDLE;
        break;
      }
      break;

     default:
      /* case IN_NORMAL: */
      if (rtU.error_signal != 0.0) {
        rtDW.is_NORMAL = IN_NO_ACTIVE_CHILD;
        rtDW.is_c3_Chart = IN_ERROR;
      } else if (rtDW.is_NORMAL == IN_IDLE) {
        if (rtU.key_mode == 1.0) {
          rtDW.is_NORMAL = IN_RUN;
          rtDW.was_NORMAL = IN_RUN;
        }

        /* case IN_RUN: */
      } else if (rtU.key_mode == 2.0) {
        rtDW.is_NORMAL = IN_IDLE;
        rtDW.was_NORMAL = IN_IDLE;
      }
      break;
    }
  }

  /* End of Chart: '<Root>/Chart' */
}

/* Model initialize function */
void Chart_initialize(void)
{
  /* (no initialization code required) */
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
